home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 001a / tm301_2.zip / TOOLBOX2.SCR < prev    next >
Text File  |  1992-01-03  |  5KB  |  188 lines

  1. ;
  2. ; TOOLBOX2.SCR (c) Copyright 1990-1992 by White River Software.
  3. ; All right reserved.
  4. ;
  5. ; Date written: 10 May 1990
  6. ;
  7. ;
  8. ; This toolbox defines three I/O procedures and four 'is' type
  9. ; procedures.
  10. ;
  11. ; To use this toolbox, you should add the line
  12. ;    #include "toolbox2.scr"
  13. ; at the beginning of your script file.  This will increase the file
  14. ; size of the compiled script file .TMS by about 2K.  To minimum the
  15. ; overhead, you should cut and paste the procedures that you used
  16. ; into your script file.  For example, the <InputN> and <ReadN>
  17. ; procedures may be excluded.
  18. ;
  19. ; Summary:
  20. ;
  21. ;   GetN s,n
  22. ;   ; get <n> characters from remote system or until CR is detected
  23. ;
  24. ;   InputN s,n
  25. ;   ; get <n> characters from keyboard or until [Enter] is detected,
  26. ;   ; the characters are printed to the local screen
  27. ;
  28. ;   ReadN s,n
  29. ;   ; read <n> characters from file or until end-if-line is detected
  30. ;
  31. ;   isalpha ch,result    ; check if <ch> is a letter
  32. ;   isdigit ch,result    ; check if <ch> is a digit
  33. ;   isalnum ch,result    ; check if <ch> is a letter or a digit
  34. ;   iscntl  ch,result    ; check if <ch> is a control character
  35. ;
  36.  
  37.  
  38. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  39. ;
  40. ; GetN s,n
  41. ; function: get <n> characters into <s> from remote system or until CR
  42. ;           is detected
  43. ; remark:   This procedure can be used to wait for one character
  44. ;           input by using  GetN ch,1
  45. ;           CR is discarded
  46. ;           BackSpace deletes the last character and the length of
  47. ;           the string is recalcuated
  48. ;
  49. Procedure GetN string s,integer n
  50. integer i
  51. string ch
  52. s = ""
  53. ch = ""
  54. i = 0
  55. While i<n and ch<>"^M"
  56.    repeat
  57.       GetCh ch
  58.    until success
  59.    concat s,ch
  60.    if ch="^H"           ; BackSpace is displayed to screen
  61.       if i=0
  62.          print " ",     ; move back the correct position
  63.       else
  64.          i = i-1;
  65.       endif
  66.    else
  67.       i = i+1
  68.    endif
  69.    if i<n and ch<>"^M"
  70.    endif
  71. EndWhile
  72. EndProc
  73.  
  74.  
  75. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  76. ;
  77. ; InputN s,n
  78. ; function: get <n> characters into <s> from keyboard or until [Enter]
  79. ;           is pressed
  80. ; remark:   This procedure can be used to wait for one character
  81. ;           input by using  InputN ch,1
  82. ;           [Enter] is discarded
  83. ;           BackSpace deletes the last character and the length of
  84. ;           the string is recalcuated
  85. ;           The characters are printed to the local screen but are not
  86. ;           sent to the remote system.
  87. ;           A line feed is supplied when [Enter] is pressed.
  88. ; caution:  Once you do not need keyboard input any more, you should
  89. ;           use the
  90. ;               Clear Key
  91. ;           statement to give up keyboard control
  92. ;
  93. Procedure InputN string s,integer n
  94. integer i
  95. string ch
  96. s = ""
  97. ch = ""
  98. i = 0
  99. While i<n and ch<>"^M"
  100.    repeat
  101.       InputCh ch
  102.    until success
  103.    concat s,ch
  104.    if ch="^H"
  105.       if i>0
  106.          i = i-1
  107.          print ch,
  108.       endif
  109.    else
  110.       i = i+1
  111.       print ch,
  112.    endif
  113.    if i<n and ch<>"^M"
  114.       repeat
  115.          InputCh ch
  116.       until success
  117.    endif
  118. EndWhile
  119. if ch="^M"
  120.    print
  121. endif
  122. EndProc
  123.  
  124.  
  125. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  126. ;
  127. ; ReadN s,n
  128. ; function: read <n> characters into <s> from file or until CR-LF
  129. ;           end-of-line sequence is detected
  130. ; remark:   CR-LF sequence is discarded
  131. ;
  132. Procedure ReadN string s,integer n
  133. integer i
  134. string ch
  135. s = ""
  136. ch = ""
  137. i = 0
  138. while i<n and ch<>"^M"
  139.    ReadCh ch
  140.    concat s,ch
  141.    i = i+1
  142. EndWhile
  143. if ch="^M"
  144.    Readch ch                   ; discard CR-LF sequence
  145. endif
  146. EndProc
  147.  
  148.  
  149. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  150. ;
  151. ; isalpha ch,result
  152. ; function: <result> is non-zero if <ch> is a character
  153. ;
  154. Procedure isalpha string ch,integer result
  155. strpos "ABCDEFGHIJKLMNOPQRSTUVWXYZ",ch,result
  156. EndProc
  157.  
  158.  
  159. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  160. ;
  161. ; isdigit ch,result
  162. ; function: <result> is non-zero if <ch> is a digit
  163. ;
  164. Procedure isdigit string ch,integer result
  165. strpos "1234567890",ch,result
  166. EndProc
  167.  
  168. ; isalnum ch,result
  169. ; function: <result> is non-zero if <ch> is a digit or character
  170. ;
  171. Procedure isalnum string ch,integer result
  172. isdigit ch,result
  173. if not result
  174.    isalpha ch,result
  175. endif
  176. EndProc
  177.  
  178.  
  179. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  180. ;
  181. ; iscntl ch,result
  182. ; function: <result> is non-zero if <ch> is a control character
  183. ;
  184. Procedure iscntl string ch,integer result
  185. strpos "^A^B^C^D^E^F^G^H^I^J^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z",ch,result
  186. EndProc
  187.  
  188.